<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('reports', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('举报者ID');
            $table->morphs('reportable'); // 支持多态：可以举报帖子、回复、用户等
            $table->string('reason')->comment('举报原因：spam（垃圾信息）、abuse（辱骂）、inappropriate（不当内容）、other（其他）');
            $table->text('description')->nullable()->comment('举报描述');
            $table->enum('status', ['pending', 'processing', 'resolved', 'rejected'])->default('pending')->comment('状态：pending待处理、processing处理中、resolved已处理、rejected已拒绝');
            $table->unsignedBigInteger('admin_id')->nullable()->comment('处理管理员ID');
            $table->text('admin_comment')->nullable()->comment('管理员处理意见');
            $table->timestamp('processed_at')->nullable()->comment('处理时间');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('admin_id')->references('id')->on('users')->onDelete('set null');
            // morphs() 方法已经自动创建了 reportable_type 和 reportable_id 的索引，不需要重复创建
            $table->index('status');
            $table->index('user_id');
            $table->index('created_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('reports');
    }
};
